<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>#{bundle.province}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form >
               <script type="text/javascript">  
                    function handleSaveProvince(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgProvince.hide();  
                        }  
                    }

                    function handleDeleteProvince(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgConfirmation.hide();  
                        }  
                    }

                    function componenKeyPress(e) {
                        var code = (e.keyCode ? e.keyCode : e.which);
                        if(code==13) {
                            submitProv.jq.click();
                            e.preventDefault();
                        }
                    }
                    
                //    setFocus('${focus}');
                    
                </script>  

                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}"
                                         icon="ui-icon-document" rendered="#{menuBean.cekButtonAccess(19,'INS;')}"
                                         action="#{provinceBean.newData()}"  
                                         oncomplete="dlgProvince.show()"
                                         process="@this" update=":#{utilityBean.findClientId('displayProvince')}"> 
                            <pe:resetEditableValues for="displayProvince"/>
                        </p:commandButton>

                        <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgProvince.show()"
                                         actionListener="#{provinceBean.openData()}"  rendered="#{menuBean.cekButtonAccess(19,'OPN;')}" 
                                         icon="ui-icon-disk" 
                                         update=":#{utilityBean.findClientId('displayProvince')}" > 
                        </p:commandButton>

                        <p:commandButton value="#{bundle.btnDelete}" icon="ui-icon-trash" rendered="#{menuBean.cekButtonAccess(19,'DEL;')}"
                                         onclick="dlgConfirmation.show()" /> 

                       <!-- <p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/>-->
                    </p:toolbarGroup>
                </p:toolbar>
                <br />
                <p:dataTable var="province" value="#{provinceBean.provinces}" id="dtProvinces"
                             selection="#{provinceBean.selectedData}" selectionMode="single" resizableColumns="true"
                             rowKey="#{province.provinceId}" rowIndexVar="noUrut" paginator="true" rows="10" paginatorPosition="bottom" 
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="5,10,15,30">
                     <p:column style="width: 10px">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                 </p:column>
                     <p:column style="width:75px" sortBy="#{province.provinceCode}">
                         <f:facet name="header">#{bundle.globalCode}</f:facet>
                         <h:outputText value="#{province.provinceCode}" />
                    </p:column>
                    <p:column style="width:250px" sortBy="#{province.provinceName}">
                        <f:facet name="header">#{bundle.province}</f:facet>
                        <h:outputText value="#{province.provinceName}" />
                    </p:column>
                    <p:column style="width:250px" sortBy="#{province.countryId}">
                        <f:facet name="header">#{bundle.country}</f:facet>
                        <h:outputText value="#{provinceBean.findCountryName(province.countryId)}" />
                </p:column>
                </p:dataTable>

                <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                                 header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgConfirmation">
                    <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                        <f:facet name="footer">
                            <p:commandButton value="#{bundle.btnYes}" update="dtProvinces" process="@this"
                                             oncomplete="handleDeleteProvince(xhr, status, args)"  
                                             actionListener="#{provinceBean.delete()}" />  
                            <p:commandButton value="#{bundle.btnCancel}" onclick="dlgConfirmation.hide()" type="button" /> 
                        </f:facet>
                    </h:panelGrid>   
                </p:confirmDialog> 
            </h:form>
            <p:dialog header="#{bundle.province}" widgetVar="dlgProvince" closable="true" dynamic="true" modal="true" appendToBody="true">
                    <p:ajax immediate="true" event="close" listener="#{provinceBean.handleClose}"/>
                    <h:form>

                    <h:panelGrid id="displayProvince" columns="2" styleClass="addELIT">
                        
                        <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.globalCode} :" />
                        <h:panelGroup>                            
                            <p:inputText rendered="#{provinceBean.insertedData!=null}" value="#{provinceBean.insertedData.provinceCode}" 
                                         label="#{bundle.globalCode}" size="10" 
                                         required="#{provinceBean.insertedData!=null}" />  
                                
                        </h:panelGroup>
                         
                        <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.globalName} :" />
                        <h:panelGroup>                            
                            <p:inputText rendered="#{provinceBean.insertedData!=null}" value="#{provinceBean.insertedData.provinceName}" 
                                         label="#{bundle.globalName}" size="25" 
                                         required="#{provinceBean.insertedData!=null}" />  
                                
                        </h:panelGroup>

                        <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.country} :" />
                        <h:panelGroup>   
                            <p:selectOneMenu value="#{provinceBean.insertedData.countryId}" 
                                             style="width: 170px" tabindex="1" rendered="#{provinceBean.insertedData!=null}"
                                             label="#{bundle.country}" required="#{provinceBean.insertedData!=null}" requiredMessage="#{bundle.country} #{bundle.requiredInput}" >
                                <f:selectItem itemLabel="#{bundle.Select} #{bundle.country}" itemValue="" />
                                <f:selectItems value="#{provinceBean.avaibleCountry}"  />
                            </p:selectOneMenu>
                        </h:panelGroup>
                    </h:panelGrid>

                    <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                        <f:facet name="footer">
                            <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{provinceBean.save()}" rendered="#{menuBean.cekButtonAccess(19,'UPD;')}"
                                             update=":#{utilityBean.findClientId('dtProvinces')}" widgetVar="submitProv"
                                             oncomplete="handleSaveProvince(xhr, status, args)"/>
                            <p:commandButton immediate="true" value="#{bundle.btnClose}" oncomplete="dlgProvince.hide()" icon="ui-icon-document"/>
                        </f:facet>
                    </h:panelGrid>
                        </h:form>
                </p:dialog> 
             
        </ui:composition>    
    </h:body>
</html>
